import { get } from '@/utils/request';

export interface DashboardStats {
  tenants?: {
    total: number;
    active: number;
    inactive: number;
  };
  users: {
    total: number;
    active: number;
    inactive: number;
  };
  logins: {
    total: number;
    success: number;
    failed: number;
    uniqueUsers: number;
    successRate: string;
  };
  files: {
    total: number;
    totalSize: number;
    totalSizeMB: string;
  };
  server: {
    platform: string;
    arch: string;
    hostname: string;
    cpus: number;
    totalMemory: string;
    freeMemory: string;
    uptime: string;
    nodeVersion: string;
  };
}

export interface LoginTrend {
  date: string;
  total: number;
  success: number;
  failed: number;
}

export interface ServerStatus {
  cpu: {
    user: number;
    system: number;
  };
  memory: {
    rss: string;
    heapTotal: string;
    heapUsed: string;
    heapUsedPercent: string;
  };
  system: {
    totalMemory: string;
    freeMemory: string;
    usedMemory: string;
    memoryUsagePercent: string;
    uptime: string;
    loadavg: number[];
    cpuCount: number;
  };
  timestamp: number;
}

/**
 * 获取仪表盘统计数据
 */
export const getDashboardStats = () => {
  return get<DashboardStats>('/dashboard/stats');
};

/**
 * 获取登录趋势数据
 */
export const getLoginTrend = () => {
  return get<LoginTrend[]>('/dashboard/login-trend');
};

/**
 * 获取服务器状态
 */
export const getServerStatus = () => {
  return get<ServerStatus>('/dashboard/server-status');
};

